package core.controller.cmds;

import core.controller.CommandController;
import core.dal.AdminFunctionality;
import exceptions.UserNotFoundException;
import exceptions.WrongPasswordException;

public class CreateUserCMD implements ICmd{

	AdminFunctionality functionality;
	final String level = "Admin";
	ICmd nextCMD;
	
	CommandController cc;
	
	public CreateUserCMD(CommandController commandController, AdminFunctionality aF){
		this.cc = commandController;
		functionality = aF;
	}
	
	@Override
	public void setNextCmd(ICmd nextCmd) {
		nextCMD = nextCmd;
		
	}

	@Override
	public void execute(String cmd) {
		if (cmd.equals("createUser")) {
			String cpr;
			String oprNavn;


			cc.getTUI().showOutput("Enter Name: ");
			oprNavn = cc.getTUI().getInput();
			cc.getTUI().showOutput("Enter CPR (ddmmyy-xxxx): ");
			cpr = cc.getTUI().getInput();
			

			try {
					functionality.createUser(oprNavn, cpr);
					cc.getTUI().showOutput("USER CREATED");
				
				
			} catch (UserNotFoundException e) {
				cc.getTUI().showOutput(e.getMessage());
			} 

		}

		if (nextCMD != null) {
			nextCMD.execute(cmd);
		}
	}

	@Override
	public String getInfo() {
		return "createUser - Create a new user";
		
	}

	@Override
	public String getLevel() {
		return this.level;
		
	}
}
